home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
lang
/
genrsp11
/
genrsp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-31
|
7KB
|
157 lines
//-------------------------------------------------------------------------
// GENRSP v1.0 Version 1.0
// Copyright (c) 1995 Eric Coolman, Simple Minded Software
// Contact via internet at: eric.coolman@mcc.uti.com
//-------------------------------------------------------------------------
// This is a simple replacement for Borland's MAKERSP.EXE. I find this
// utility more useful and functional than Borland's version. It still
// handles printf() style string formatting, as well as fixing a few bugs
// found in MAKERSP ie. printing the tailing ampersand (&), requiring
// manual editing afterwards. I found MAKERSP cumbersome in which it
// requires an input file to start out with as well. This is where GENRSP
// differs from MAKERSP... rather than taking an input file, you give it
// wildcard specs, and on top of that, you can stack filespecs by
// separating them with a semicolon, giving full paths to the filespecs
// (the paths will be used in the response file). Type "GENRSP.EXE" by
// itself at the dos prompt for example syntax.
//-------------------------------------------------------------------------
// Although this code is copyrighted, permission is granted for unlimited
// and use, modification, and distribution, as long as the original author
// (Eric Coolman, Simple Minded Software) is creditted as such (in
// documentation), and the original copyright notice (above) remains intact.
//
// Any usage of this code and/or utility is at own risk! Sorry for the
// ugly code, but I didn't feel like spending any time on it.
// Command-line compile with: BCC -mt -lt -O1 genrsp.c
//-------------------------------------------------------------------------
// Revisions:
// March 30, 1995 - v1.0 - Initial release.
// March 31, 1995 - v1.1 - Ooops. See v1.1 notes below.
//-------------------------------------------------------------------------
#include <string.h> // various string manip funcs.
#include <stdio.h> // ...printf() functions
#include <stdlib.h> // atoi(), _fullpath()
#include <dir.h> // struct ffblk, findfirst/next(), fnsplit/merge()
char helptext[] =
"\nGENRSP Version 1.1 Copyright (c) 1995 Simple Minded Software"
"\nGenerates a response file for use with Borland's TLIB."
"\n\nGENRSP \"printf format string\" [[drive:][path]filemask[ ...]]"
"\n\n\"printf format string\" - format specifier string (as in printf())"
"\n[drive:][path]filemask(s) - specifies files to be LIB'ed"
"\nExample command: - GENRSP \"\\n-+%%%%s &\" *.obj >> objlist.rsp"
"\n - GENRSP \"\\n-+%%%%s &\" *.c;*.cpp >> objlist.rsp";
char *AbsPath(char *inpath, char *infile, char *abspath)
{
char drive[MAXDRIVE], dir[MAXDIR], relative[MAXPATH];
fnsplit(inpath, drive, dir, NULL, NULL); // remove any filespecs
fnmerge(relative, drive, dir, NULL, NULL); // reconstruct dir only
strcat(relative, infile); // concat curfile
return _fullpath(abspath, relative, MAXPATH); // normalize the path
}
// Input : See above.
// Return: 0 = No Error, 1 = No files found, 2 = Error in command line
int main(int argc, char *argv[])
{
char buffer[MAXPATH], formatted[MAXPATH], abs[MAXPATH], *token, *ext;
int i, rc = 1, done = 0;
struct ffblk ffblk;
//-- v1.1 : Was only checking asking for 1 input parm. Now make sure there
// : are at least 2.
if (argc < 3)
{
printf(helptext);
return 2;
}
memset(buffer, 0, MAXPATH);
memset(abs, 0, MAXPATH);
for (i = 1; i < argc-2; i++) // concatinate all parameters except last
strcat(strcat(buffer, argv[i]), " ");
strcat(buffer, argv[i]); // avoid concatinating space to end
// replace control code strings with actual control codes
while ((token = strchr(buffer, '\\')) != NULL)
{
*token = ' '; // kill the slash
switch (*(token + 1))
{
case 'n': // newline (linefeed)
*(token + 1) = '\n';
break;
case 'r': // carriage return
*(token + 1) = '\r';
break;
case 't': // horizontal tab
*(token + 1) = '\t';
break;
// The rest useless, but just in case:
case 'v': // vertical tab
*(token + 1) = '\v';
break;
case 'b': // backspace
*(token + 1) = '\b';
break;
case 'a': // audible bell
*(token + 1) = '\a';
break;
case 'f': // form feed
*(token + 1) = '\f';
break;
case '\\': // backslash
*(token + 1) = '\\';
break;
case '\'': // single quote (apostrophe)
*(token + 1) = '\'';
break;
case '\"': // double quote
*(token + 1) = '\"';
break;
case 'x': // hex string
i = atoi(token + 2);
*(token + 1) = (((i / 10) << 4) + (i % 10));
*(token + 2) = ' ';
if (i > 9)
*(token + 3) = ' ';
break;
}
}
token = strtok(argv[argc-1], ";"); // start unstacking filelists
do
{
done = findfirst(token, &ffblk, 0);
if (! done)
{
rc = 0; // found a match, so we'll have an .RSP file
while (! done)
{
if (*abs) // start printing after second match
{ // reformat so it doesn't mess up on redirection
sprintf(formatted, buffer, abs);
printf(strupr(formatted));
}
AbsPath(token, ffblk.ff_name, abs);
//-- v1.1 : Wouldn't parse files with no extension properly. It will now.
if ((ext = strrchr(abs, '.')) != NULL) // has extension
*ext = 0; // remove extension
strcat(abs, ".OBJ"); // change to .obj
done = findnext(&ffblk);
}
}
//-- v1.1 : Remmed this out so it doesn't get redirected to output file,
// : in case more found entries (stacked wildcards) follow.
// else
// printf("\nPattern \"%s\" not found.", token);
} while ((token = strtok(NULL, ";")) != NULL);
if (*abs) // if we found any matches at all, we'll have one left over
{
if (strchr(buffer, '&'))
*strrchr(buffer, '&') = ' ';
sprintf(formatted, buffer, abs);
printf(formatted);
}
return rc;
}